home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / WINDOWS / CLIPSTAC.ARJ / CSTEST.CPP < prev    next >
C/C++ Source or Header  |  1992-05-24  |  5KB  |  136 lines

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include"stdwin.h"
  4. #include"csapi.h"
  5.  
  6.         char message[50];
  7.  
  8. class myApp : public WinAppStdWindow
  9.     {
  10.     HWND hWndClipStac;
  11.     BOOL ClipStacActive;
  12. public:
  13.     myApp(char *name) : WinAppStdWindow(name)
  14.         {
  15.         ClipStacActive = FALSE;
  16.         DelWinStyle(WS_VISIBLE);
  17.         WM_CLIPSTACREGISTER = RegisterWindowMessage(szWM_CLIPSTACREGISTER);
  18.         WM_CLIPSTACPUSH = RegisterWindowMessage(szWM_CLIPSTACPUSH);
  19.         WM_CLIPSTACPOP = RegisterWindowMessage(szWM_CLIPSTACPOP);    
  20.         WM_CLIPSTACFIND = RegisterWindowMessage(szWM_CLIPSTACFIND);
  21.         WM_CLIPSTACGET = RegisterWindowMessage(szWM_CLIPSTACGET);
  22.         WM_CLIPSTACEXIT = RegisterWindowMessage(szWM_CLIPSTACEXIT);
  23.         WM_CLIPSTACDEREGISTER = RegisterWindowMessage(szWM_CLIPSTACREGISTER);
  24.         WM_CLIPSTACNUMITEMS = RegisterWindowMessage(szWM_CLIPSTACNUMITEMS);
  25.         }
  26.     void WMCREATE(WinAppMsg&)
  27.         {
  28.         SendMessage(0xffff,WM_CLIPSTACREGISTER,hWnd,0L);
  29.         SetTimer(hWnd,1,5000,NULL);     // wait for 5 seconds for ClipStac to respond
  30.         }
  31.     void WMTIMER(WinAppMsg& m)
  32.         {
  33.         if(m.wParam == 1)
  34.             {
  35.             KillTimer(hWnd,1);              // ClipStac too slow or not running...
  36.             MessageBox(hWnd,"ClipStac not found!","CSTEST",MB_OK);
  37.             PostMessage(hWnd,WM_CLOSE,0,0L);
  38.             }
  39.         if(m.wParam == 2)
  40.             {
  41.             KillTimer(hWnd,2);
  42.             MessageBox(hWnd,"CSTest exiting.","CSTEST",MB_OK);
  43.             PostMessage(hWnd,WM_CLOSE,0,0L);
  44.             }
  45.         }
  46.         
  47.     void WMCLOSE(WinAppMsg&)
  48.         {
  49.         if(ClipStacActive)              // if ClipStac active, let it know we're history
  50.             SendMessage(hWndClipStac,WM_CLIPSTACDEREGISTER,hWnd,0L);
  51.         DestroyWindow(hWnd);
  52.         }
  53.     void WMDESTROY(WinAppMsg&)
  54.         {
  55.         PostQuitMessage(0);
  56.         }
  57.         
  58.     void WMUSER(WinAppMsg &m)
  59.         {
  60.         if(m.msg == WM_CLIPSTACREGISTER)
  61.             {
  62.             if(HIWORD(m.lParam) == hWnd)
  63.                 {
  64.                 KillTimer(hWnd,1);
  65.                 ClipStacActive = TRUE;
  66.                 hWndClipStac = LOWORD(m.lParam);
  67.  
  68.                 if(hWndClipStac)                // if ClipStac handle retrieved
  69.                     {
  70.                     int numItems = SendMessage(hWndClipStac,WM_CLIPSTACNUMITEMS,0,0L);
  71.                         // have it push the Clipboard contents onto the stack
  72.                     if(SendMessage(hWndClipStac,WM_CLIPSTACPUSH,0,0L))
  73.                         {
  74.                         MessageBox(hWnd,"Stack pushed!","CSTEST",MB_OK);
  75.                             // now pop the stack
  76.                         if(SendMessage(hWndClipStac,WM_CLIPSTACPOP,0,0L))
  77.                             MessageBox(hWnd,"Stack popped!","CSTEST",MB_OK);
  78.                         }
  79.                     else
  80.                         MessageBox(hWnd,"0 return from PUSH","CSTEST",MB_OK);
  81.                     
  82.                         // now get the identifying info on item 0
  83.                     LPSTR stuff = (LPSTR)SendMessage(hWndClipStac,WM_CLIPSTACGET,0,0L);
  84.                     if(stuff)
  85.                         {
  86.                         char buf[200];
  87.                         sprintf(buf,"Info on item[%d] (of %d): %Fs",0,numItems,(LPSTR)stuff);
  88.                         MessageBox(hWnd,buf,"CSTEST",MB_OK);
  89.  
  90.                             // now find the item # that contains all this
  91.                         char *p = strstr(buf,":\\");
  92.                         if(!p)
  93.                             p = strstr(buf,"(Own");
  94.                         if(p)
  95.                             {
  96.                             p--;
  97.                             LPSTR lpstr = p;
  98.                             int index = SendMessage(hWndClipStac,WM_CLIPSTACFIND,0,(LONG)lpstr);
  99.                             if(index != -1)
  100.                                 {
  101.                                 sprintf(buf,"index = %d",index);
  102.                                 MessageBox(hWnd,buf,"CSTEST",MB_OK);
  103.                                 }
  104.                             }
  105.                         SetTimer(hWnd,2,5000,NULL);     // wait for 5 seconds for ClipStac to terminate
  106.                         }
  107.                     }
  108.                 }
  109.             return;
  110.             }
  111.         if(m.msg == WM_CLIPSTACEXIT)
  112.             {
  113.             ClipStacActive = FALSE;
  114.             MessageBox(hWnd,"ClipStac has terminated","CSTEST",MB_OK);
  115.             }
  116.         }
  117.     };
  118.  
  119.  
  120. int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int)
  121.     {
  122.     myApp MyWin("CSTest");
  123.     if(MyWin.GetPrevInstance())
  124.         {
  125.         MessageBox(NULL,"CSTest already running!","CSTest",MB_OK);
  126.         return 0;
  127.         }
  128.     MyWin.Display(SW_HIDE);                    // open the window
  129.     return MyWin.Run();                 // process any messages
  130.     }
  131.  
  132.  
  133.  
  134.  
  135.  
  136.